package org.igeek.atomqq.widget;

import org.igeek.atomqq.R;
import org.igeek.atomqq.domain.FriendCategory;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

/** 
 * 好友分组
 * @author <a href="http://hangxin1940.cnblogs.com">hangxin1940@gmail.com</a>
 * @time 2012-2-5 下午06:43:55 
 */
public class FriendCategoryView extends LinearLayout {
	
	private FriendCategory category;
	private TextView tvName;
	private TextView tvCount;
	
	
	private boolean flash=false;
	//闪烁
	private Handler handler=new Handler(){
		@Override
		public void handleMessage(Message msg) {
			
			if(flash){
				tvCount.setVisibility(View.VISIBLE);
				tvName.setVisibility(View.VISIBLE);
				flash=false;
				handler.sendEmptyMessageDelayed(0, 300);
			}else{
				tvCount.setVisibility(View.INVISIBLE);
				tvName.setVisibility(View.INVISIBLE);
				flash=true;
				handler.sendEmptyMessageDelayed(0, 500);
			}
			
		}
	};
	
	public FriendCategoryView(Context context) {
		super(context);
		
		//填充布局
		LayoutInflater infater=(LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		infater.inflate(R.layout.widget_friend_category, this, true);
		
		
		tvName=(TextView) findViewById(R.id.widget_friend_category_tvFriendCategoryName);
		tvCount=(TextView) findViewById(R.id.widget_friend_category_tvFriendCategoryMemberCount);
		
	}

	public void setCategory(FriendCategory category) {
		this.category = category;
		
		tvName.setText(category.getName());
		tvCount.setText("["+category.getOnlineCount()+"/"+category.getFriendCount()+"]");
	
		/**闪烁*/
		if(category.hasNewMessage()){
			handler.sendEmptyMessageDelayed(0, 300);
		}else{
			handler.removeMessages(0);
		}
	}

	public FriendCategory getCategory() {
		return category;
	}
	

}
